package com.pms.servlet;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pms.entity.Ideas;
import com.pms.service.IdeaService;

public class EditIdeaServlet extends HttpServlet {


	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setCharacterEncoding("utf-8");
		
		String ideaId=request.getParameter("ideaId");
		System.out.println("ideaId:"+ideaId);
		
		IdeaService ideas=new IdeaService();
		Ideas idea=ideas.findById(ideaId);
	
		request.setAttribute("idea", idea);
		
		request.getRequestDispatcher("/WEB-INF/editIdea.jsp").forward(request, response);
		
	}
	
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		String idid=req.getParameter("idid");
		String title=req.getParameter("title");
		String note=req.getParameter("note");
		System.out.println(idid+title+note);
		
		new IdeaService().editIdea(idid,title,note);
		resp.sendRedirect("idea.jspx");
		
	}

}
